﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_gold_sellGold : System.Web.UI.Page
{
    db_users user = new db_users();
    db_gold gold = new db_gold();

    public string cardID = "";
    public string goldNum = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx"); // 此处用户权限验证
        cardID = Request.QueryString["id"];
        goldNum = gold.selectCardGold(cardID).Tables[0].Rows[0]["gold"].ToString();
    }
    protected void btn_user_Click(object sender, EventArgs e)
    {
        string name = "";
        if (tb_name.Text.Trim().Equals(""))
        {
            // tb_name.Text;Response.Write("<script language=javascript>alert('增加成功');</script>");
            Response.Write("<script language=javascript>alert('请输入用户名');</script>");
            res();
            tb_name.Focus();
            return;
        }
        else
        {
            name = tb_name.Text.Trim();
        }
        DataSet ds = new DataSet();
        ds = user.selectUserONE_username(name);
        if (ds.Tables[0].Rows.Count == 0) {
            Response.Write("<script language=javascript>alert('用户不存在');</script>");
            tb_name.Focus();
            return;
        }
        else
        {
            lbl_uName.Text = ds.Tables[0].Rows[0]["userName"].ToString();
            lbl_uID.Text = ds.Tables[0].Rows[0]["userID"].ToString();
        }
    }
    protected void btn_sell_Click(object sender, EventArgs e)
    {
        if (lbl_uID.Text.Equals("编号"))
        {
            Response.Write("<script language=javascript>alert('输入用户名，然后点击查询');</script>");
            res();
            tb_name.Focus();
            return;
        }
        else
        {
            string uID = lbl_uID.Text.Trim();
            if (gold.isCardSell(cardID))
            {
                Response.Write("<script language=javascript>alert('此卡已经出售！');</script>");
                return;
            }
            else
            {
                if (gold.sellGoldCard(cardID, uID))
                {
                    Response.Write("<script language=javascript>alert('出售成功！');</script>");
                    res();
                }
                else
                {
                    Response.Write("<script language=javascript>alert('失败！');</script>");
                }
            }
        }
    }

    private void res()
    {
        lbl_uName.Text = "用户名";
        lbl_uID.Text = "编号";
    }
    protected void btn_close_Click(object sender, EventArgs e)
    {

        this.Response.Write("<script>window.opener.location.reload();window.opener=null;window.close();</script>");
    }
}